package com.homer.android.sdk.action.device.humiture;

import java.util.List;

import com.homer.android.sdk.action.device.sensor.EspActionSensorGetStatusListInternetDB;
import com.homer.android.sdk.action.device.status.IEspStatusHumiture;
import com.homer.android.sdk.action.device.status.IEspStatusSensor;
import com.homer.android.sdk.command.device.humiture.EspCommandHumitureGetStatusListInternet;
import com.homer.android.sdk.command.device.humiture.IEspCommandHumitureGetStatusListInternet;
import com.homer.android.sdk.db.greenrobot.daos.GenericDataDB;
import com.homer.android.sdk.type.devcie.status.EspStatusHumiture;
import com.homer.iot.esptouch.udp.EspDeviceType;

public class EspActionHumitureGetStatusListInternetDB extends EspActionSensorGetStatusListInternetDB implements
IEspActionHumitureGetStatusListInternetDB
{
@Override
public IEspStatusSensor parseStatus(GenericDataDB dataInDB)
{
    StringBuilder sb = new StringBuilder(dataInDB.getData());
    String[] datas = sb.toString().split(",");
    double x = Double.parseDouble(datas[0]);
    double y = Double.parseDouble(datas[1]);
    long at = dataInDB.getTimestamp();
    IEspStatusSensor statusHumiture = new EspStatusHumiture();
    statusHumiture.setX(x);
    statusHumiture.setY(y);
    statusHumiture.setAt(at);
    return statusHumiture;
}

@Override
public GenericDataDB parseStatus(long deviceId, IEspStatusSensor statusSensor)
{
    double x = statusSensor.getX();
    double y = statusSensor.getY();
    String data = x + "," + y;
    long timestamp = statusSensor.getAt();
    GenericDataDB genericDataDB = new GenericDataDB(null, deviceId, timestamp, data, 0);
    return genericDataDB;
}

@SuppressWarnings("unchecked")
@Override
public List<IEspStatusSensor> doCommandSensorGetStatusListInternet(String deviceKey, long startTimestampFromServer,
    long endTimestampFromServer)
{
    IEspCommandHumitureGetStatusListInternet command = new EspCommandHumitureGetStatusListInternet();
    return (List<IEspStatusSensor>)(List<?>)command.doCommandHumitureGetStatusListInternet(deviceKey,
        startTimestampFromServer,
        endTimestampFromServer);
}

@SuppressWarnings("unchecked")
@Override
public List<IEspStatusHumiture> doActionHumitureGetStatusListInternetDB(long deviceId, String deviceKey,
    long startTimestamp, long endTimestamp, long interval)
{
    return (List<IEspStatusHumiture>)(List<?>)super.doActionSensorGetStatusListInternetDB(deviceId,
        deviceKey,
        startTimestamp,
        endTimestamp,
        interval,
        EspDeviceType.HUMITURE);
}

}

